package com.wh1200.xmlless.test.model

import com.wh1200.mybatis.xmlless.XmlLessMapper
import com.wh1200.mybatis.xmlless.annotations.PropertyMapping
import com.wh1200.mybatis.xmlless.annotations.XmllessMethod
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param

/**
 *
 * @author wuhao
 * @date 2024/1/25 11:01
 * @since v0.0.0
 * @version 1.0
 */
@Mapper
interface JoinEntityDAO : XmlLessMapper<com.wh1200.xmlless.test.model.JoinObjectEntity> {

  fun insert(entity: com.wh1200.xmlless.test.model.JoinObjectEntity)

  fun update(entity: com.wh1200.xmlless.test.model.JoinObjectEntity)

  fun findById(@Param("id") id: Int): com.wh1200.xmlless.test.model.JoinObjectEntity?

  fun findAll(): List<com.wh1200.xmlless.test.model.JoinObjectEntity>

  fun deleteById(@Param("id") id: Int)

  @XmllessMethod(
      conditions = ["parent.id2 = id"]
  )
  fun findByParent(@Param("id") id: Int): List<com.wh1200.xmlless.test.model.JoinObjectEntity>


  @XmllessMethod(
      conditions = ["parent.grandParent.id3 = id"]
  )
  fun findByGrandParent(@Param("id") id: Int): List<com.wh1200.xmlless.test.model.JoinObjectEntity>


  @XmllessMethod(
      conditions = ["p.p.id3 = id"]
  )
  fun findByGrandParent2(@Param("id") id: Int): List<com.wh1200.xmlless.test.model.JoinObjectEntity>


  @XmllessMethod
  fun findByGrandParent3(@Param("id") id: Int): List<com.wh1200.xmlless.test.model.JoinObjectEntityVO>

}

class JoinObjectEntityVO {
  @PropertyMapping("p.grandParent.name")
  val grandParentName: String? = null
}
